package com.ybkj.daijia;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

public class CityList {

    @SuppressWarnings("unchecked")
    public static List<Map<String, Object>> getCitys() throws DocumentException, IOException {

        String[] cityzimu = {"A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "P",
            "Q", "R", "S", "T", "W", "X", "Y", "Z"};

        Resource resource = new ClassPathResource("city.xml");
        SAXReader reader = new SAXReader();
        Document doc = reader.read(resource.getInputStream());

        Iterator<Element> iter = doc.getRootElement().elementIterator();

        int zimu = 0;
        List<Map<String, Object>> mapList = new ArrayList<Map<String, Object>>();

        while (iter.hasNext()) {

            Map<String, Object> map = new HashMap<String, Object>();

            map.put("cityZimu", cityzimu[zimu]);
            zimu++;

            List<String> cityList = new ArrayList<String>();

            Element node = iter.next();
            Iterator<Element> iter2 = node.elementIterator();
            while (iter2.hasNext()) {
                Element node2 = iter2.next();

                cityList.add(node2.getText());

            }

            map.put("citys", cityList);
            mapList.add(map);

        }

        return mapList;
    }

}  